<?php

namespace App\Admin\Actions\Player;

use App\Models\Player;
use Dcat\Admin\Actions\Response;
use Dcat\Admin\Grid\RowAction;
use Vinkla\Hashids\Facades\Hashids;

class UpgradeLink extends RowAction
{
    protected string $title = '更新链接';

    public function handle(): Response
    {
        $player = Player::ofAdmin()->find($this->getKey());

        $slug = Hashids::connection('player')->encode($player->application_id, $player->id, rand(1, 999));
        $player->update(['slug' => $slug]);

        return $this->response()->success('链接更新成功')->refresh();
    }

    public function confirm(): array
    {
        return [
            '更新链接',
            '如果是选手链接被封，可以使用此功能，如果是二级域名被封，此操作无效，如果是海报被封，也无效',
        ];
    }
}
